// Platinum Net Test.cpp : Defines the entry point for the console application.
//


#include "platinum.h"
#include <sstream>
#include <iostream>

int main(int argc, char* argv[])
{
	int iPort;
	std::stringstream mybuf;
	using namespace Platinum::Net;
	if(argc >= 2){
		mybuf << argv[1]; //Since atoi functions just a little different on Linux, Windows and Mac, we should just use a stream buffer for the conversions
	    mybuf >> iPort;
	
		UDP::Listener MyListener(iPort);
		Packet* MyPacket;
		bool done = false;
		
		while(!done){
			MyPacket = MyListener.Listen();
			std::cout << "Packet Recieved From: " << MyPacket->IP << std::endl;
			std::cout << "Data: " << MyPacket->Data << std::endl;
			if(MyPacket->Data == "QUIT")
				done = true;
			
			delete(MyPacket);
		}
	}else{
			
			std::cout << "This program listens on a given port, for UDP packets, and reports details of each packet recieved" << std::endl;
			std::cout << "It can be deactivated by sending it a packet containing only the word QUIT" << std::endl;
			std::cout << "Usage: port" << std::endl;
	}
	return 0;
}

